﻿using System;
using System.Collections.Generic;

namespace AppMain
{
    public class MoveEvent : BaseEvent<MoveEventData>
    {

        protected override void onProcess()
        {
            ActionRole role = this.Action.role;
            MoveData moveData = MoveData.New();
            moveData.moveStatus = (Move_Status)this.m_data.reqState;
            moveData.distance = this.m_data.distance;
            moveData.height = this.m_data.height;
            moveData.speed = this.m_data.speed;
            moveData.time = this.m_data.durtion;
            //转换数据 主要是要转换一些方向 等信息
            int faceFlag = role.AttrMap.getAttr<int>(RoleAttr.LookFlag).Value;
            if (moveData.moveStatus == Move_Status.SelfMove)
            {
                moveData.dir.x = this.m_data.dirType == (int)E_DirType.Back ? -1 * faceFlag : 1 * faceFlag;
            }
            else if (moveData.moveStatus == Move_Status.HitBack)
            {
                //受击转向 
                E_DirType dirType = (E_DirType)(this.m_data.dirType);
                if (dirType == E_DirType.Caster2Target && this.Action.damageData != null)
                {
                    moveData.dir.x = this.Action.damageData.dir.x;
                    moveData.dir.z = this.Action.damageData.dir.z;
                    int flag = moveData.dir.x < 0 ? 1 : -1;
                    this.Action.role.AttrMap.changeAttr<int>(RoleAttr.LookFlag, flag);
                }
                else
                {
                    moveData.dir.x = -1 * faceFlag;
                }
            }
            else if (moveData.moveStatus == Move_Status.HitCurve)
            {
                E_DirType dirType = (E_DirType)(this.m_data.dirType);
                if (dirType == E_DirType.Caster2Target && this.Action.damageData != null)
                {
                    moveData.dir.x = this.Action.damageData.dir.x;
                    moveData.dir.z = this.Action.damageData.dir.z;
                    int flag = moveData.dir.x < 0 ? 1 : -1;
                    this.Action.role.AttrMap.changeAttr<int>(RoleAttr.LookFlag, flag);
                }
                else if (dirType == E_DirType.HitAir)
                {
                    //浮空 只赋值高度 已经赋值
                    if (this.Action.damageData != null)
                    {
                        int flag = this.Action.damageData.dir.x < 0 ? 1 : -1;
                        this.Action.role.AttrMap.changeAttr<int>(RoleAttr.LookFlag, flag);
                    }
                }
                else
                {
                    moveData.dir.x = -1 * faceFlag;
                }
            }
            moveData.dir.Normalize();
            role.moveWidget.doMove(moveData);
        }

    }

}
